package cn.fl.expatriate.controller;

import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.user.facade.system.api.ISysUsrApiService;
import cmm.user.facade.system.dto.SysUsrDTO;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.logger.eum.LogExceptionEnum;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.cmm.cache.framework.utils.PropertiesCacheUtils;
import cn.fl.commons.result.ResponseData;
import cn.fl.expatriate.condition.ExpBizManRecQC;
import cn.fl.expatriate.service.IExpBizManRecService;
import cn.fl.expatriate.vo.ExpBizManRecVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.preloan.dto.expatriate.ExpBizManRecDTO;
import cn.fl.preloan.enums.LogBusinessTypeEnum;
import cn.fl.preloan.expatriate.IExpBizManRecApiService;
import cn.fl.project.condition.PrjPrdDtlQueryCondition;
import cn.fl.project.dto.PrjPrdDtlDTO;
import cn.fl.project.service.IProjectApiService;
import cn.fl.system.constant.SysLogConstant;
import com.alibaba.fastjson.JSON;
import com.lionbridge.log.ext.ExtSlf4jLogger;
import com.lionbridge.log.ext.ExtSlf4jLoggerBuilder;
import com.lionbridge.log.ext.LogTypeEnum;
import fl.constant.facade.framework.constant.SystemConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Description: 外派业务人员记录表 控制层
 */
@Slf4j
@Controller
@RequestMapping("/expatriate/expBizManRec")
public class ExpBizManRecController extends BaseController {

	private static ExtSlf4jLogger extSlf4jLogger = ExtSlf4jLoggerBuilder.create()
			.setBusinessType(LogBusinessTypeEnum.PRE_LOAN.getCode())
			.setSubBusinessType(LogBusinessTypeEnum.FLOW.getCode())
			.setLogType(LogTypeEnum.BUSINESS)
			.setLogger(log).build();

	/**
	 * ExpBizManRec 服务层BEAN
	 */
	@Autowired
	private IExpBizManRecService expBizManRecService;

	@Resource(name = "expBizManRecService")
	private IExpBizManRecApiService expBizManRecApiService;

	@Autowired
	private IProjectApiService projectApiService;

	/**
	 * 用户服务
	 */
	@Autowired
	private ISysUsrApiService sysUsrApiService;

	/**
	 * 到列表页面
	 */
	@RequestMapping(value = "/toListPage.do", method = { RequestMethod.GET})
	public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView view = new ModelAndView("expatriate/expBizManRec/list");
//		BaseLogUtils.info(logger, "toListPage", "跳转到列表页面.", CurrentThreadContext.getCurrentUserName());
        return view;
	}

	/**
	 * 到修改页面
	 */
	@RequestMapping(value = "/toModifyPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toModifyPage(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		ModelAndView view = new ModelAndView("expatriate/expBizManRec/modify");
		view.addObject("id", id);
//		BaseLogUtils.info(logger, "toModifyPage", "跳转到修改页面.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
		return view;
	}

	/**
	 * 初始化列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String searchName = request.getParameter("demo.name");
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		ExpBizManRecQC qc = new ExpBizManRecQC();
		if (StringUtils.isNotEmpty(searchName)) {
			//TODO SOMTHING
		}
		page.setCondition(qc);

		//TODO SOMETHING
		Pager pager = new Pager();//this.expBizManRecService.searchListPage(page);
		List<ExpBizManRecVO> list = (List<ExpBizManRecVO>) pager.getResultList();
		ListPageVO<ExpBizManRecVO> listPage = new ListPageVO<ExpBizManRecVO>(list, pager.getTotalCount());
//		BaseLogUtils.info(logger, "initList", "查询数据完成. DATA:" + JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
		return listPage;
	}

	/**
	 * 删除数据
	 */
	@RequestMapping(value = "/removeById.do", method = {RequestMethod.POST })
	@ResponseBody
	public DataResultVO removeById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			return result;
		}
		try {
			this.expBizManRecService.removeById(Long.valueOf(id));
//			BaseLogUtils.info(logger, "removeById", "删除数据.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
//			BaseLogUtils.info(logger, "removeById", "删除数据失败.[id="+id+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
//			BaseLogUtils.error(logger, "removeById", "删除数据失败.[id="+id+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}

		return result;
	}

	/**
	 * 得到一条记录
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getById.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
//			BaseLogUtils.error(logger, "getById", "获取数据,主键不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		
		try {
			ExpBizManRecVO vo = this.expBizManRecService.selectById(Long.valueOf(id));
			if(null == vo){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
//				BaseLogUtils.info(logger, "getById", "获取数据,数据不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			}
			result.setData(vo);
//			BaseLogUtils.info(logger, "getById", "获取数据.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
//			BaseLogUtils.info(logger, "getById", "获取失败.[id="+id+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
//			BaseLogUtils.error(logger, "getById", "获取失败.[id="+id+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}

	/**
	 * 新增
	 */
	@RequestMapping(value = "/add.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object add(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String name = request.getParameter("name");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
		ExpBizManRecVO entity = null;
		try {
			entity = new ExpBizManRecVO();
			//TODO ADD PARAM
			Long id = this.expBizManRecService.add(entity);
			result.setData(id);
//			BaseLogUtils.info(logger, "add", "新增数据.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
//			BaseLogUtils.info(logger, "add", "新增数据失败.DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
//			BaseLogUtils.error(logger, "add", "新增数据失败.DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}

		return result;
	}

	/**
	 * 修改
	 */
	@RequestMapping(value = "/modify.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object modify(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		String name = request.getParameter("name");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_UPDATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
//			BaseLogUtils.info(logger, "modify", "修改数据,主键不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		ExpBizManRecVO entity = null;
		try {
			entity = new ExpBizManRecVO();
			entity.setId(Long.valueOf(id));
			//entity.setName(name);
			//TODO ADD PARAM
			boolean success = this.expBizManRecService.modify(entity);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
//				BaseLogUtils.info(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
			}
//			BaseLogUtils.info(logger, "modify", "修改成功.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
//			BaseLogUtils.info(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
//			BaseLogUtils.error(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}

	@RequestMapping(value = "/saveExpBizManRec.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object saveExpBizManRec(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		String prjId = request.getParameter("prjId");
		String aptTypCd = request.getParameter("aptTypCd");
		String usrId = request.getParameter("usrId");
		String rlNm = request.getParameter("rlNm");
		String usrNm = request.getParameter("usrNm");
		if (StringUtils.isEmpty(prjId)) {
			result = new DataResultVO(BaseConstant.IS_YESNO_NO, "项目id不能为空！");
			return result;
		}
		if (StringUtils.isEmpty(aptTypCd)) {
			result = new DataResultVO(BaseConstant.IS_YESNO_NO, "指派类型不能为空！");
			return result;
		}
		if (StringUtils.isEmpty(usrId)) {
			result = new DataResultVO(BaseConstant.IS_YESNO_NO, "用户id不能为空！");
			return result;
		}
		if (StringUtils.isEmpty(rlNm)) {
			result = new DataResultVO(BaseConstant.IS_YESNO_NO, "用户名称不能为空！");
			return result;
		}
		if (StringUtils.isEmpty(usrNm)) {
			result = new DataResultVO(BaseConstant.IS_YESNO_NO, "登录名称不能为空！");
			return result;
		}
		try {
			ExpBizManRecVO expBizManRecVO = new ExpBizManRecVO();
			expBizManRecVO.setDataId(Long.valueOf(prjId));
			expBizManRecVO.setAptTypCd(aptTypCd);
			expBizManRecVO.setUsrId(Long.valueOf(usrId));
			expBizManRecVO.setUsrNm(usrNm);
			expBizManRecVO.setRlNm(rlNm);
			BaseLogUtils.newWebLogger("===新增/修改Start===expBizManRecVO:" + JSON.toJSONString(expBizManRecVO)).info();
			boolean res = this.expBizManRecService.saveExpBizManRec(expBizManRecVO);
			BaseLogUtils.newWebLogger("===新增/修改End===res:" + res).info();
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.newWebLogger("操作失败,ex:" + JSON.toJSONString(ex)).info();
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.newWebLogger("系统错误,ex:" + JSON.toJSONString(ex)).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0002);
		}
		return result;
	}

	/**
	 * 查询发送短信选择人员列表
	 */
	@RequestMapping(value = "/toExpBizManRecInfo.do", method = {RequestMethod.GET, RequestMethod.POST})
	public ModelAndView toExpBizManRecInfo(HttpServletRequest request, HttpServletResponse response) {
		String dataId = request.getParameter("dataId");
		String lsCntNo = request.getParameter("lsCntNo");
		ModelAndView view = new ModelAndView("expatriate/expBizManRec/sendExpBizManRecInfo");
		view.addObject("dataId", dataId);
		view.addObject("lsCntNo", lsCntNo);

		List<Long> dataIdList = new ArrayList<>();
		List<String> aptTypCdList = new ArrayList<>();
		aptTypCdList.add("2");
		aptTypCdList.add("3");
		if(StringUtils.isNotEmpty(dataId)){
			PrjPrdDtlQueryCondition prjPrdDtlQC = new PrjPrdDtlQueryCondition();
			prjPrdDtlQC.setPrjId(Long.valueOf(dataId));
			prjPrdDtlQC.setSysCd(CurrentThreadContext.getCurrentSysCd());
			prjPrdDtlQC.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
			prjPrdDtlQC.setIsDel(BaseConstant.IS_YESNO_NO);
			BaseLogUtils.newWebLogger("===查询项目产品信息Start===prjPrdDtlQC:" + JSON.toJSONString(prjPrdDtlQC)).info();
			List<PrjPrdDtlDTO> prjPrdDtlDTOList = this.projectApiService.selectPrjPrdDtlList(prjPrdDtlQC);
			BaseLogUtils.newWebLogger("===查询项目产品信息Start===prjPrdDtlDTOList-size:" + (CollectionUtils.isEmpty(prjPrdDtlDTOList)?0:prjPrdDtlDTOList.size())).info();
			if (CollectionUtils.isEmpty(prjPrdDtlDTOList)) {
				throw new BaseException("未查询到项目产品！");
			}
			for (PrjPrdDtlDTO prjPrdDtlDTO : prjPrdDtlDTOList) {
				if (CollectionUtils.isEmpty(dataIdList) || !dataIdList.contains(prjPrdDtlDTO.getId())) dataIdList.add(prjPrdDtlDTO.getId());
			}
			dataIdList.add(Long.valueOf(dataId));
		}
		ExpBizManRecQC qc = new ExpBizManRecQC();
		if (CollectionUtils.isNotEmpty(dataIdList)) {
			qc.setDataIdList(dataIdList);
		}
		qc.setAptTypCdList(aptTypCdList);
		BaseLogUtils.newWebLogger("===查询发送短信选择人员列表Start===qc:" + JSON.toJSONString(qc)).info();
		List<ExpBizManRecVO> expBizManRecList = this.expBizManRecService.searchList(qc);
		BaseLogUtils.newWebLogger("===查询发送短信选择人员列表End===qc:" + JSON.toJSONString(expBizManRecList)).info();
		if (CollectionUtils.isNotEmpty(expBizManRecList)){
			for (ExpBizManRecVO expBizManRecVO : expBizManRecList){
				if(StringUtils.isNotEmpty(expBizManRecVO.getUsrId())){
					BaseLogUtils.newWebLogger("===查询客户经理手机号Start===qc:" + JSON.toJSONString(expBizManRecVO.getUsrId())).info();
					SysUsrDTO sysUsrDTO = this.sysUsrApiService.selectSysUsrById(expBizManRecVO.getUsrId(), PropertiesCacheUtils.getProperty(SystemConstant.FL_SERVICE_CD), PropertiesCacheUtils.getProperty(SystemConstant.FL_ORG_CD));
					BaseLogUtils.newWebLogger("===查询客户经理手机号End===qc:" + JSON.toJSONString(sysUsrDTO)).info();
					if(null!=sysUsrDTO && StringUtils.isNotEmpty(sysUsrDTO.getMp())){
						expBizManRecVO.setMp(sysUsrDTO.getMp());
					}
				}
			}
		}
		view.addObject("expBizManRecList", expBizManRecList);
		return view;
	}

	/**
	 * 发送短信
	 */
	@RequestMapping(value = "/sendSMS.do", method = {RequestMethod.POST})
	@ResponseBody
	public DataResultVO sendSMS(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		Long staTime = System.currentTimeMillis();
		BaseLogUtils.newWebLogger("===发送短信请求参数:" + this.getRequestParameter(request));
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);

		String expIds = request.getParameter("expIds");
		String lsCntNo = request.getParameter("lsCntNo");
		BaseLogUtils.newWebLogger("===发送短信参数===res:" + JSON.toJSONString(expIds)).info();

		if(StringUtils.isEmpty(expIds)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("参数不完整！");
			return result;
		}
		if(StringUtils.isEmpty(lsCntNo)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("合同号不能为空！");
			return result;
		}
		try {
			boolean success = this.expBizManRecService.sendSMS(expIds,lsCntNo);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("发送短信失败!");
			}else{
				result.setSuccess(BaseConstant.IS_YESNO_YES);
				result.setInfo("发送短信成功!");
			}
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.newWebLogger("操作失败,ex:" + JSON.toJSONString(ex.getMessage())).info();
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_OPERATE_FAIL);
			BaseLogUtils.newWebLogger("系统错误,ex:" + JSON.toJSONString(ex)).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0002);
		}
		Long endTime = System.currentTimeMillis();
		BaseLogUtils.newWebLogger("发送短信成功操作完成.耗时:" + (endTime - staTime) + "毫秒");
		return result;
	}


	@RequestMapping(value = "/saveDyLicExpBizManRec.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object saveDyLicExpBizManRec(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		extSlf4jLogger.info("保存抵押外派人员记录信息，请求参数：{}", JSON.toJSON(request.getParameterMap()));
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		String prjPrdDtlId = request.getParameter("prjPrdDtlId");
		String aptTypCd = request.getParameter("aptTypCd");
		String usrId = request.getParameter("usrId");
		String rlNm = request.getParameter("rlNm");
		String usrNm = request.getParameter("usrNm");
		String dataTypCd = request.getParameter("dataTypCd");
		String id = request.getParameter("id");
		String licRgnPrCd = request.getParameter("licRgnPrCd");
		String licRgnCyCd = request.getParameter("licRgnCyCd");
		try {
			ExpBizManRecDTO dto = new ExpBizManRecDTO();
			if (StringUtils.isNotEmpty(id)){
				dto.setId(Long.valueOf(id));
				dto.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
				dto.setMdfUsrName(CurrentThreadContext.getCurrentUserName());
				dto.setMdfTm(new Date());
			} else {
				dto.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
				dto.setCrtUsrNm(CurrentThreadContext.getCurrentUserName());
				dto.setCrtTm(new Date());
			}
			if (StringUtils.isNotEmpty(licRgnPrCd)){
				dto.setLicRgnPrCd(licRgnPrCd);
			}
			if (StringUtils.isNotEmpty(licRgnCyCd)){
				dto.setLicRgnCyCd(licRgnCyCd);
			}
			if (StringUtils.isNotEmpty(usrId)){
				dto.setUsrId(Long.valueOf(usrId));
			}
			if (StringUtils.isNotEmpty(prjPrdDtlId)){
				dto.setDataId(Long.valueOf(prjPrdDtlId));
			}
			dto.setDataTypCd(dataTypCd);
			dto.setAptTypCd(aptTypCd);
			dto.setUsrNm(usrNm);
			dto.setRlNm(rlNm);
			extSlf4jLogger.info("保存抵押外派人员记录信息，dto：{}", JSON.toJSON(dto));
			ResponseData<Boolean> responseData = expBizManRecApiService.saveExpBizManRec(dto);
			extSlf4jLogger.info("保存抵押外派人员记录信息，result：{}", JSON.toJSON(responseData));
			if (!ResponseData.SUCCESS_CODE.equals(responseData.getCode()) || null == responseData.getCode() || !responseData.getData()){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("保存失败，请核实");
			}
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			extSlf4jLogger.info("保存抵押外派人员记录信息失败，ex：{}", JSON.toJSON(ex));
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			extSlf4jLogger.info("保存抵押外派人员记录信息失败，系统错误ex：{}", JSON.toJSON(ex));
		}
		return result;
	}

	/**
	 * 发起抵押外派流程
	 * @author gaohy
	 **/
	@RequestMapping(value = "/mortgateExpFlowStart.do", method = {RequestMethod.POST})
	@ResponseBody
	public Object mortgateExpFlowStart(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		extSlf4jLogger.setKeywords("抵押外派流程").info("发起抵押外派流程Start.request:{},usrNm:{}", this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
		DataResultVO result = null;
		//获取参数 付款ID
		String capPayId = request.getParameter("capPayId");
		try {
			if (StringUtils.isEmpty(capPayId)) {
				result = new DataResultVO(BaseConstant.IS_YESNO_NO, SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
				extSlf4jLogger.info("发起抵押外派流程,参数为空！usrNm:{}", CurrentThreadContext.getCurrentUserName());
				return result;
			}
			extSlf4jLogger.info("发起抵押外派流程Start.id:{}", capPayId);
			result = this.expBizManRecService.mortgateExpFlowStart(Long.valueOf(capPayId));
		} catch (BaseException e) {
			result = new DataResultVO(BaseConstant.IS_YESNO_NO, e.getMessage());
			extSlf4jLogger.info("发起抵押外派流程失败.capPayId:{},异常信息:{}", capPayId, e);
		} catch (Exception e) {
			result = new DataResultVO(BaseConstant.IS_YESNO_NO, "系统错误,请联系管理员！");
			extSlf4jLogger.error("发起抵押外派流程异常.capPayId:{},异常信息:{}", capPayId, e);
		}
		extSlf4jLogger.setKeywords("抵押外派流程").info("发起抵押外派流程End.capPayId:{},result:{},usrNm:{}", capPayId, JSON.toJSONString(result), CurrentThreadContext.getCurrentUserName());
		return result;
	}

}

